﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.MarketUI {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Events.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import GameMode.*;
    import flash.text.*;
    import Display.aswingui.*;
    import Modules.factory.ui.*;

    public class TabbedCatalogUI extends ItemCatalogUI {

        private var m_categoryNames:Array;
        private var m_numTabs:int;
        private var m_currentTabIndex:int;

        public function TabbedCatalogUI(){
            this.m_numTabs = 0;
            this.m_currentTabIndex = 0;
        }
        public function get numTabs():int{
            return (this.m_numTabs);
        }
        public function set numTabs(_arg1:int):void{
            if (_arg1 == this.m_numTabs){
                return;
            };
            this.m_numTabs = _arg1;
            this.updateCategoryNames();
        }
        public function get categoryNames():Array{
            if (this.m_categoryNames == null){
                this.updateCategoryNames();
            };
            return (this.m_categoryNames);
        }
        private function updateCategoryNames():void{
            this.m_categoryNames = new Array();
            var _local1:int;
            while (_local1 < this.numTabs) {
                this.m_categoryNames.push(this.getTabIdFromIndex(_local1));
                _local1++;
            };
        }
        protected function getTabIdFromIndex(_arg1:int):String{
            return ((this.getTabbedCatalogKey() + _arg1));
        }
        protected function getIndexFromTabId(_arg1:String):int{
            if (_arg1 == null){
                return (0);
            };
            return (int(_arg1.substr(this.getTabbedCatalogKey().length, _arg1.length)));
        }
        public function getTabbedCatalogKey():String{
            return ("");
        }
        override protected function makeBackground():void{
            var _local1:DisplayObject = (new (TabbedCatalog.assetDict["tab_bg"])() as DisplayObject);
            ASwingHelper.setSizedBackground(this, _local1);
        }
        override protected function get layoutGap():Number{
            return (-3);
        }
        override protected function renderTab(_arg1:String):void{
            var _local3:DisplayObject;
            var _local2:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            _local3 = this.getTabBackground(_arg1);
            ASwingHelper.setSizedBackground(_local2, _local3);
            var _local4:int = this.getIndexFromTabId(_arg1);
            var _local5:String = this.getLocalizedTabName(_local4);
            var _local6:String = EmbeddedArt.TITLE_FONT;
            var _local7 = 14;
            var _local8:uint = EmbeddedArt.darkBlueTextColor;
            var _local9:JTextField = ASwingHelper.makeTextField(_local5, _local6, _local7, _local8);
            var _local10:TextFormat = new TextFormat();
            _local10.size = 16;
            TextFieldUtil.formatSmallCaps(_local9.getTextField(), _local10);
            var _local11:JPanel = ASwingHelper.centerElement(_local9);
            _local2.name = _arg1;
            m_tabsDict[_local2] = _arg1;
            _local2.append(_local11);
            _local2.addEventListener(MouseEvent.CLICK, this.changeCategoryFromTab, false, 0, true);
            _local2.addEventListener(MouseEvent.ROLL_OVER, this.showToolTip, false, 0, true);
            _local2.addEventListener(MouseEvent.ROLL_OUT, hideToolTip, false, 0, true);
            m_tabsPanel.append(_local2);
        }
        protected function refreshTabs():void{
            var _local1:String;
            m_tabsPanel.removeAll();
            for each (_local1 in this.m_categoryNames) {
                this.renderTab(_local1);
            };
        }
        protected function getTabBackground(_arg1:String):DisplayObject{
            if (_arg1 == this.getTabIdFromIndex(this.getCurrentTabIndex())){
                return (new (TabbedCatalog.assetDict["tab_active"])());
            };
            return (new (TabbedCatalog.assetDict["tab_inactive"])());
        }
        public function setCurrentTabIndex(_arg1:int):void{
            var _local2:String = this.getTabIdFromIndex(_arg1);
            switchType(_local2);
        }
        public function getCurrentTabIndex():int{
            return (this.m_currentTabIndex);
        }
        protected function loadItemsForTab(_arg1:int):Array{
            return (new Array());
        }
        override protected function loadAvailableItems():void{
            m_items = this.loadItemsForTab(this.getCurrentTabIndex());
        }
        override protected function showToolTip(_arg1:MouseEvent):void{
            var _local2:JPanel = (_arg1.currentTarget as JPanel);
            var _local3:String = m_tabsDict[(_arg1.currentTarget as JPanel)];
            var _local4:IntPoint = _local2.getGlobalLocation();
            var _local5:Number = _local4.x;
            var _local6:Object = new Object();
            _local6.category = _local3;
            _local6.posX = _local5;
            _local6.xOffset = 55;
            _local6.yOffset = 15;
            dispatchEvent(new GenericObjectEvent(GenericObjectEvent.ROLLOVER_MARKET_CATEGORY, _local6));
        }
        override protected function switchActiveTab(_arg1:String, _arg2:String):void{
            var _local3:int = this.getIndexFromTabId(_arg2);
            if (this.m_currentTabIndex == _local3){
                return;
            };
            var _local4:String = this.getTabIdFromIndex(this.m_currentTabIndex);
            var _local5:JPanel = (m_tabsPanel.getChildByName(_local4) as JPanel);
            var _local6:DisplayObject = (new (TabbedCatalog.assetDict["tab_inactive"])() as DisplayObject);
            ASwingHelper.setSizedBackground(_local5, _local6);
            var _local7:JPanel = (m_tabsPanel.getChildByName(_arg2) as JPanel);
            var _local8:DisplayObject = (new (TabbedCatalog.assetDict["tab_active"])() as DisplayObject);
            ASwingHelper.setSizedBackground(_local7, _local8);
            var _local9:int = this.getIndexFromTabId(_arg2);
            this.m_currentTabIndex = _local9;
        }
        protected function changeCategoryFromTab(_arg1:MouseEvent):void{
            var _local2:String;
            var _local3:GameMode;
            if (!Global.isVisiting()){
                _local2 = _arg1.currentTarget.name;
                this.setCurrentTabIndex(this.getIndexFromTabId(_local2));
                _local3 = Global.world.getTopGameMode();
                if ((_local3 is GMPlaceMapResource)){
                    Global.world.addGameMode(new GMPlay());
                };
                _arg1.stopImmediatePropagation();
                _arg1.stopPropagation();
            };
        }
        override protected function makeShelf(_arg1:Array):MarketScrollingList{
            return (new TabbedMarketScrollingList(_arg1, FactoryCell, 0, 7, 1));
        }
        override protected function onMarketDown(_arg1:MouseEvent):void{
            var _local6:GMDefault;
            var _local2:GameMode = Global.world.getTopGameMode();
            var _local3:Point = new Point(Global.ui.mouseX, Global.ui.mouseY);
            var _local4:Array = Global.ui.m_bottomUI.getObjectsUnderPoint(_local3);
            var _local5:int;
            _local5 = 0;
            while (_local5 < _local4.length) {
                if ((_local4[_local5] is TabbedCatalog.assetDict["tab_bg"])){
                    if ((_local2 is GMDefault)){
                        _local6 = (_local2 as GMDefault);
                        _local6.turnOffObject();
                    };
                    _arg1.stopImmediatePropagation();
                    _arg1.stopPropagation();
                };
                _local5++;
            };
        }
        override protected function makeTopTabs(_arg1:Array=null):void{
            var _local2:String;
            var _local3:JPanel;
            var _local4:JPanel;
            var _local5:JPanel;
            var _local6:JPanel;
            var _local7:String;
            for each (_local2 in _arg1) {
                this.renderTab(_local2);
            };
            m_tabsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0));
            m_tabsPanel.setPreferredWidth(703);
            ASwingHelper.setEasyBorder(m_tabsPanel, 0, 25);
            m_catalog.addEventListener(MouseEvent.MOUSE_DOWN, this.onMarketDown, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_MOVE, this.onMarketDown, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_OVER, onMarketOver, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_OUT, onMarketOut, false, 0, true);
            _local3 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.RIGHT);
            _local4 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            m_closeButton = ASwingHelper.makeMarketCloseButton();
            m_closeButton.addActionListener(closeCatalog, 0, true);
            _local4.appendAll(m_closeButton, ASwingHelper.verticalStrut(10));
            _local3.append(_local4);
            _local3.append(ASwingHelper.horizontalStrut(15));
            _local5 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            _local5.append(ASwingHelper.horizontalStrut(15));
            _local6 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            if (this.m_overrideTitle != ""){
                _local7 = ZLoc.t("Dialogs", (m_overrideTitle + "_menu"));
            } else {
                _local7 = ZLoc.t("Dialogs", (m_type + "_menu"));
            };
            m_sectionTitle = ASwingHelper.makeTextField("", EmbeddedArt.TITLE_FONT, 30, EmbeddedArt.titleColor, 5);
            var _local8:JTextField = ASwingHelper.makeTextField(_local7, EmbeddedArt.TITLE_FONT, 24, EmbeddedArt.titleColor, 5);
            _local8.filters = EmbeddedArt.newtitleFilters;
            var _local9:TextFormat = new TextFormat();
            _local9.size = 30;
            TextFieldUtil.formatSmallCaps(_local8.getTextField(), _local9);
            ASwingHelper.setEasyBorder(_local6, 3, 0, 2);
            _local6.appendAll(_local8);
            m_topPanel.append(_local5, BorderLayout.WEST);
            m_topPanel.append(_local6, BorderLayout.CENTER);
            m_topPanel.append(_local3, BorderLayout.EAST);
            this.append(m_topPanel);
            this.append(m_tabsPanel);
            this.append(ASwingHelper.verticalStrut(-5));
            ASwingHelper.prepare(this);
        }
        public function getLocalizedTabName(_arg1:int):String{
            return ("");
        }
        override public function refreshShelf():void{
            this.setCurrentTabIndex(this.getCurrentTabIndex());
        }

    }
}//package Display.MarketUI 
